<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<body style="overflow:hidden;">
<div id="grid-div">
    <!-- 隐藏区域：存放查询条件 -->
    <form id="hiddenQueryForm" action="<%=path%>/inventoryChange/exportExcel" method="POST" style="display:none;">

        <!-- 物料编号与名称 -->
        <input id="materialId" name="materialId" value=""/>
        <!-- 库区-->
        <input id="areaId" name="areaId" value="">
        <!-- 开始时间-->
        <input id="startTime" name="startTime" value=""/>
        <!-- 结束时间-->
        <input id="endTime" name="endTime" value="">
        <!-- 服务类型-->
        <input id="serviceType" name="serviceType" value=""/>
        <!-- 操作人-->
        <input id="oprationMan" name="oprationMan" value="">
    </form>
    <div class="query_box" id="yy" title="查询选项">
            <form id="queryForm" style="max-width:100%;">
			 <ul class="form-elements">
				<li class="field-group field-fluid3">
					<label class="inline" for="materialId" style="margin-right:20px;width:100%;">
						<span class="form_label" style="width:65px;">物料：</span>
						<input type="text" id="materialId" name="materialId" style="width: calc(100% - 70px);" placeholder="物料">
					</label>			
				</li>
				<li class="field-group field-fluid3">
					<label class="inline" for="areaId" style="margin-right:20px;width:100%;">
						<span class="form_label" style="width:65px;">库区：</span>
						<input type="text" id="areaId" name="areaId" style="width: calc(100% - 70px);" placeholder="库区">
					</label>					
				</li>
				<li class="field-group field-fluid3">
					<label class="inline" for="serviceType" style="margin-right:20px;width:100%;">
						<span class="form_label" style="width:65px;">业务类型：</span>
						<input type="text" id="serviceType" name="serviceType" style="width: calc(100% - 70px);" placeholder="业务类型">
					</label>					
				</li>
				<li class="field-group-top field-group field-fluid3">
					<label class="inline" for="startTime" style="margin-right:20px;width:100%;">
						<span class="form_label" style="width:65px;">开始时间：</span>
						<input class="form-control date-picker" id="startTime" name="startTime" style="width:calc(100% - 70px);" type="text" placeholder="开始时间" class="span10"/>
					</label>					
				</li>
				<li class="field-group field-fluid3">
					<label class="inline" for="endTime" style="margin-right:20px;width:100%;">
						<span class="form_label" style="width:65px;">结束时间：</span>
						<input class="form-control date-picker" id="endTime" name="endTime" style="width:calc(100% - 70px);" type="text" placeholder="结束时间" class="span10"/>
					</label>			
				</li>				
				<li class="field-group field-fluid3">
					<label class="inline" for="oprationMan" style="margin-right:20px;width:100%;">
						<span class="form_label" style="width:65px;">操作人：</span>
						<input id="oprationMan" name="oprationMan" style="width:calc(100% - 70px);" type="text" placeholder="操作人" class="span10"/>
					</label>			
				</li>
				
			</ul>
			<div class="field-button" style="">
					<div class="btn btn-info" onclick="queryOk();">
				        <i class="ace-icon fa fa-check bigger-110"></i>查询
			        </div>
				    <div class="btn" onclick="reset();"><i class="ace-icon icon-remove"></i>重置</div>
				    <a style="margin-left: 8px;color: #40a9ff;" class="toggle_tools">收起 <i class="fa fa-angle-up"></i></a>
		        </div>
		  </form>		 
    </div>
    <div id="fixed_tool_div" class="fixed_tool_div">
        <div id="__toolbar__" style="float:left;overflow:hidden;"></div>
    </div>
    <!--    物料信息表格 -->
    <table id="grid-table" style="width:100%;height:100%;"></table>
    <!-- 	表格分页栏 -->
    <div id="grid-pager"></div>
</div>
</body>
<script type="text/javascript" src="<%=path%>/static/js/techbloom/wms/stock/inventory.js"></script>
<script type="text/javascript">
    var context_path = '<%=path%>';
    var oriData;      //表格数据
    var _grid;        //表格对象
    var dynamicDefalutValue="da3fbf783eb84f8f9f7190acbe2b3405";
    $(function  (){
        $(".toggle_tools").click();
    });
    $(".date-picker").datetimepicker({format: 'YYYY-MM-DD HH:mm',useMinutes:true,useSeconds:true});
    $(function () {
        //工具栏
        $("#__toolbar__").iToolBar({
            id: "__tb__01",
            items: [
                {label: "导出", disabled: (${sessionUser.queryQx} == 1 ? false : true),onclick:exportExcel,iconClass:' icon-share'},
                {label: "打印", disabled: (${sessionUser.queryQx} == 1 ? false : true),onclick:printList,iconClass:' icon-print'}
            ]
    });
        //初始化表格
        _grid = jQuery("#grid-table").jqGrid({
            url: context_path + '/inventoryChange/toList',
            datatype: "json",
            colNames: ['主键', '库存变动日期', '单据编号', '物料编号', '业务类型','物料名称','操作人','库区','质检单号', 'RFID编码','库位','盘号','盘大小'],
            colModel: [
                {name: 'id', index: 'id', width: 20, hidden: true},
                {name: 'documentTime', index: 'documentTime', width: 50},
                {name: 'documentNo', index: 'documentNo', width:50},
                {name: 'materialNo', index: 'materialNo', width: 50},
                {name: 'serviceType', index: 'serviceType', width: 30},
                {name: 'materialName', index: 'materialName', width: 30},
                {name: 'oprationMan', index: 'oprationMan', width: 30},
                {name: 'areaName', index: 'areaName', width: 50},
                {name : 'add1',index : 'add1',width : 50,
                    formatter:function(cellValu,option,rowObject){
                        return "ZJ00001";
                    }
                },
                {name : 'add2',index : 'add2',width : 50,
                    formatter:function(cellValu,option,rowObject){
                        return "RF00001";
                    }
                },
                {name : 'add3',index : 'add3',width : 50,
                    formatter:function(cellValu,option,rowObject){
                        return "库位1";
                    }
                },
                {name : 'add4',index : 'add4',width : 50,
                    formatter:function(cellValu,option,rowObject){
                        return "PH00001";
                    }
                },
                {name : 'add5',index : 'add5',width : 50,
                    formatter:function(cellValu,option,rowObject){
                        return "20*20";
                    }
                },
                /*{name: 'inAmount', index: 'inAmount', width: 60},
                {name: 'outAmount', index: 'outAmount', width: 20,},
                {name: 'restAmount', index: 'restAmount', width: 30}*/
            ],
            rowNum: 20,
            rowList: [10, 20, 30],
            pager: '#grid-pager',
            sortname: 'id',
            sortorder: "desc",
            altRows: true,
            viewrecords: true,
            //caption: "库存台账",
            autowidth: true,
            // multiselect: true,
            multiboxonly: true,
            beforeRequest:function (){
                dynamicGetColumns(dynamicDefalutValue,"grid-table",$(window).width()-$("#sidebar").width() -7);
                //重新加载列属性
            },
            loadComplete: function (data) {
                var table = this;
                setTimeout(function () {
                    updatePagerIcons(table);
                    enableTooltips(table);
                }, 0);
                oriData = data;
                $(window).triggerHandler('resize.jqGrid');
            },
            emptyrecords: "没有相关记录",
            loadtext: "加载中...",
            pgtext: "页码 {0} / {1}页",
            recordtext: "显示 {0} - {1}共{2}条数据"
        });
        //在分页工具栏中添加按钮
        jQuery("#grid-table").navGrid('#grid-pager', {
            edit: false,
            add: false,
            del: false,
            search: false,
            refresh: false
        }).navButtonAdd('#grid-pager', {
            caption: "",
            buttonicon: "ace-icon fa fa-refresh green",
            onClickButton: function () {
                //jQuery("#grid-table").trigger("reloadGrid");  //重新加载表格
                $("#grid-table").jqGrid('setGridParam',
                    {
                        postData: {queryJsonString: ""} //发送数据
                    }
                ).trigger("reloadGrid");
            }
        })
        .navButtonAdd('#grid-pager',{
            caption: "",
            buttonicon:"fa  icon-cogs",
            onClickButton : function (){
                jQuery("#grid-table").jqGrid('columnChooser',{
                    done: function(perm, cols){
                        dynamicColumns(cols,dynamicDefalutValue);
                        $("#grid-table").jqGrid( 'setGridWidth', $("#grid-div").width()-3);
                    }
                });
            }
        });

        $(window).on('resize.jqGrid', function () {
            $("#grid-table").jqGrid('setGridWidth', $("#grid-div").width() - 3);
            //$("#grid-table").jqGrid('setGridHeight', (document.documentElement.clientHeight - $("#grid-pager").height() - 195 - (!$(".query_box").is(":hidden") ? $(".query_box").outerHeight(true) : 0) ));
            $("#grid-table").jqGrid('setGridHeight', $(".container-fluid").height()-$(".query_box").outerHeight(true)-$("#fixed_tool_div").outerHeight(true)-$("#grid-pager").outerHeight(true)
            //-$("#gview_grid-table .ui-jqgrid-titlebar").outerHeight(true)
           -$("#gview_grid-table .ui-jqgrid-hbox").outerHeight(true));
        });

        $(window).triggerHandler('resize.jqGrid');
    });
    var _queryForm_data = iTsai.form.serialize($('#queryForm'));
    function queryOk() {
        if($("#queryForm #startTime").val()==""){
            layer.alert("请输入开始时间");
            return false;
        }
        if($("#queryForm #endTime").val()==""){
            layer.alert("请输入结束时间");
            return false;
        }
        if($("#queryForm #endTime").val()!="" && $("#queryForm #startTime").val()){
            //判断结束时间是否大于开始时间
            var startTime = $("#queryForm #startTime").val();
            var endTime = $("#queryForm #endTime").val();
            var d1 =  new Date(startTime.replace(/\-/g, "\/"));
            var d2 = new Date(endTime.replace(/\-/g, "\/"));
            if(d1>d2){
                layer.alert("结束时间不能等于小于开始时间");
                return false;
            }else{
                var queryParam = iTsai.form.serialize($('#queryForm'));
                //执行父窗口中的js方法：将当前窗口中的form的值传递到父窗口，并放到父窗口中隐藏的form中，接着执行刷新父窗口列表的操作
                queryInstoreListByParam(queryParam);
            }
        }
    }


    $('#queryForm .mySelect2').select2();

    $('#queryForm #materialTypeSelect').change(function () {
        $('#queryForm #materialId').val($('#queryForm #materialTypeSelect').val());
    });


    $('#queryForm #areaIdEdit').change(function () {
        $('#queryForm #areaId').val($('#queryForm #areaIdEdit').val());
    });

    function reset() {
        //var formJsonParam = $('#queryForm').serialize();
        iTsai.form.deserialize($('#queryForm'), _queryForm_data);
        $('#queryForm #areaIdEdit').select2("val", "");
        $('#queryForm #materialTypeSelect').select2("val", "");
        //var queryParam = iTsai.form.serialize($('#queryForm'));
        //执行父窗口中的js方法：将当前窗口中的form的值传递到父窗口，并放到父窗口中隐藏的form中，接着执行刷新父窗口列表的操作
        queryInstoreListByParam(_queryForm_data);
    }
    $("#queryForm #oprationMan").select2({
    placeholder: "选择操作人",
    minimumInputLength: 0, //至少输入n个字符，才去加载数据
    allowClear: true, //是否允许用户清除文本信息
    delay: 250,
    formatNoMatches: "没有结果",
    formatSearching: "搜索中...",
    formatAjaxError: "加载出错啦！",
    ajax: {
        url: context_path + "/ASNmanage/getSelectUser",
        type: "POST",
        dataType: 'json',
        delay: 250,
        data: function (term, pageNo) { //在查询时向服务器端传输的数据
            term = $.trim(term);
            return {
                queryString: term, //联动查询的字符
                pageSize: 15, //一次性加载的数据条数
                pageNo: pageNo, //页码
                time: new Date()
                //测试
            }
        },
        results: function (data, pageNo) {
            var res = data.result;
            if (res.length > 0) { //如果没有查询到数据，将会返回空串
                var more = (pageNo * 15) < data.total; //用来判断是否还有更多数据可以加载
                return {
                    results: res,
                    more: more
                };
            } else {
                return {
                    results: {}
                };
            }
        },
        cache: true
    }
});
$("#queryForm #materialId").select2({
        placeholder: "请选择物料",//文本框的提示信息
        minimumInputLength: 0,   //至少输入n个字符，才去加载数据
        allowClear: true,  //是否允许用户清除文本信息
        ajax: {
            url: context_path + "/material/getMaterialSelectList",
            dataType: "json",
            delay: 250,
            data: function (term, pageNo) {     //在查询时向服务器端传输的数据
                term = $.trim(term);
                return {
                    docId: $("#id").val(),
                    queryString: term,    //联动查询的字符
                    pageSize: 15,    //一次性加载的数据条数
                    pageNo: pageNo,    //页码
                    time: new Date()//测试
                }
            },
            results: function (data, pageNo) {
                var res = data.result;
                if (res.length > 0) {   //如果没有查询到数据，将会返回空串
                    var more = (pageNo * 15) < data.total; //用来判断是否还有更多数据可以加载
                    return {
                        results: res, more: more
                    };
                } else {
                    return {
                        results: {"id": "0", "text": "没有更多结果"}
                    };
                }

            },
            cache: true
        }
    });
$("#queryForm #areaId").select2({
        placeholder: "请选择库区",
        minimumInputLength: 0, //至少输入n个字符，才去加载数据
        allowClear: true, //是否允许用户清除文本信息
        delay: 250,
    
        formatNoMatches: "没有结果",
        formatSearching: "搜索中...",
        formatAjaxError: "加载出错啦！",
        ajax: {
            url: context_path + "/area/getSelectArea",
            type: "POST",
            dataType: "json",
            delay: 250,
            data: function (term, pageNo) { //在查询时向服务器端传输的数据
                term = $.trim(term);
                return {
                    queryString: term, //联动查询的字符
                    pageSize: 15, //一次性加载的数据条数
                    pageNo: pageNo, //页码
                    time: new Date()
                    //测试
                }
            },
            results: function (data, pageNo) {
                var res = data.result;
                if (res.length > 0) { //如果没有查询到数据，将会返回空串
                    var more = (pageNo * 15) < data.total; //用来判断是否还有更多数据可以加载
                    return {
                        results: res,
                        more: more
                    };
                } else {
                    return {
                        results: {}
                    };
                }
            },
            cache: true
        }
    });
</script>
